<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>drop</title>
</head>
<body>
  <!-- 
    1. pull(...values): 删除原数组中与value相同的元素, 返回所有删除元素的数组
          说明: 原数组发生了改变
          如: [1,3,5,3,7].pull(2, 7, 3, 7) ===> 返回值为[3,3,7] 原数组变为[1, 5]
    2. pullAll(values): 功能与pull一致, 只是参数变为数组
          如: [1,3,5,3,7].pullAll([2, 7, 3, 7]) ===> 返回值为[3,3,7] 原数组变为[1, 5]
  -->
  <script>
    Array.prototype.pull = function (...values) {
      var self = this
      if (self.length===0 || values.length===0) {
        return []
      }
      values = Array.from(new Set(values))
      var result = []
      for (let index = 0; index < self.length; index++) {
        const item = self[index];
         if (values.indexOf(item)!==-1) {
          self.splice(index, 1)
          result.push(item)
          index--
        }
      }
      return result
    }

    Array.prototype.pullAll = function (values) {
      if (!values || !Array.isArray(values)) {
        return []
      }
      return this.pull(...values)
    }
    
  </script>
  
  <script>
    var arr = [1,3,5,3,7]
    console.log(arr.pull(2, 7, 3, 7), arr)
    var arr2 = [1,3,5,3,7]
    console.log(arr2.pullAll([2, 7, 3, 7]), arr2)
  </script>
</body>
</html>